package com.ruoyi.merchant.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.vo.CouponTemplateVO;
import com.ruoyi.merchant.domain.vo.MerchantCouponBindingVO;
import com.ruoyi.merchant.service.IMerchantCouponBindingService;

/**
 * 商家优惠券绑定Controller
 * 
 * @author xperia
 */
@RestController
@RequestMapping("/merchant/coupon/binding")
public class MerchantCouponBindingController extends BaseController {
    
    @Autowired
    private IMerchantCouponBindingService merchantCouponBindingService;

    /**
     * 查询已绑定的优惠券列表
     */
    @GetMapping("/list")
    public AjaxResult list() {
        List<MerchantCouponBindingVO> list = merchantCouponBindingService.selectBindingList();
        return success(list);
    }

    /**
     * 查询可绑定的平台优惠券模板列表
     */
    @GetMapping("/available")
    public AjaxResult availableTemplates() {
        List<CouponTemplateVO> list = merchantCouponBindingService.selectAvailableTemplates();
        return success(list);
    }

    /**
     * 绑定平台优惠券模板
     */
    @Log(title = "绑定优惠券模板", businessType = BusinessType.INSERT)
    @PostMapping("/{couponId}")
    public AjaxResult bind(@PathVariable Long couponId) {
        return toAjax(merchantCouponBindingService.bindTemplate(couponId));
    }

    /**
     * 启用绑定
     */
    @Log(title = "启用绑定", businessType = BusinessType.UPDATE)
    @PutMapping("/enable/{bindingId}")
    public AjaxResult enable(@PathVariable Long bindingId) {
        return toAjax(merchantCouponBindingService.enableBinding(bindingId));
    }

    /**
     * 停用绑定
     */
    @Log(title = "停用绑定", businessType = BusinessType.UPDATE)
    @PutMapping("/disable/{bindingId}")
    public AjaxResult disable(@PathVariable Long bindingId) {
        return toAjax(merchantCouponBindingService.disableBinding(bindingId));
    }

    /**
     * 解除绑定
     */
    @Log(title = "解除绑定", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bindingId}")
    public AjaxResult Unbind(@PathVariable Long bindingId) {
        return toAjax(merchantCouponBindingService.unbindTemplate(bindingId));
    }
}

